今天我們要開始我們的工作量證明啦~
type ProofOfWork struct {
	target *big.Int
	block *Block
}
首先先說明一下我們判斷的方法,由於我們要找前綴 0 為 target 個數量
因此我們要拿我們算出來的 Hash 值和 1 後面接上 (256 - target) bit 個0 比大小
如果 < ,代表說題目就被解開惹~,反之則沒有OAO
所以我們要先創出一個給我們比較的值 0x000000000100...0 之類的
例如:
target 難度是 24 bit
因此如下圖
target = 0x0000010000000000000000000000000000000000000000000000000000000000
Hash1 = 0x7c2ecd07f155648431e0f94b89247d713c5786e1e73e953f2fe7eca39534cd6d
Hash2 = 
0x000000a7f155648431e0f94b89247d713c5786e1e73e953f2fe7eca39534cd6d
Hash1 > target ----> False
Hash2 < target ----> True
func NewProofOfWork(b *Block) *ProofOfWork {
	target := big.NewInt(1)
	target.Lsh(target, uint(256-targetBits))
    pow := &ProofOfWork{b, target}
    return pow
}
func (pow *ProofOfWork) prepareData(nonce int) []byte {
	data := bytes.Join(
		[][]byte{
			pow.block.PrevBlockHash,
			pow.block.Data,
			IntToHex(pow.block.Timestamp),
			IntToHex(int64(targetBits)),
			IntToHex(int64(nonce)),
		},
		[]byte{},
	)
	return data
}
type Block struct {
	Timestamp int64
	Data []byte
	PrevBlockHash []byte
	Hash []byte
	Nonce int
}